﻿<cfsilent>
	<cfscript>
		
		propertyAdvice = getProperty("serviceFactory").getBean("studentPropertyAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		pageAdvice = getProperty("serviceFactory").getBean("pageAdvice");
		
		event.setArg("pageTitle", "系统日志查看");
		
		currentTab = event.getArg("TabID", "labOperation");
		
		passArgs = structNew();
		 pageArgs = structNew();
		 
		 pageArray = [];
		
		tip = "";
		
		rs_all = queryNew("");
		
		/*所有日志*/
		if( currentTab eq "labAll" ){
			
			typeId = event.getArg("typeId");
			userId = event.getArg("userId");
			targetId = event.getArg("targetId");
			
			HSQL = "";
			
			if( len(typeId) ){
				HSQL = " AND t.type_id = '" & typeId & "'";	
				tip = "类型为 " & typeId;
				
			}
			
			if( len(targetId) ){
				HSQL = " AND t.target_id = '" & targetId & "'";	
				tip = "操作对象Id " & targetId;
			}
			
			if( len(userId) ){
				HSQL = " AND t.user_id = '" & userId & "'";	
				tip = "操作人Id " & userId;
			}
			
			
			sql = "SELECT substr(t.log_id,5,5) log_id, t.type_id, t.user_id,t.target_id,
						t.user_id, t.log_content, 
						t.log_ip, t.log_time, t.target_id, t.cls_id, 
						b.user_name targetName, a.user_name userName  
				  FROM T_LOGINFO t 
					  INNER JOIN t_user b ON b.user_id = t.target_id 
					  INNER JOIN t_user a ON a.user_id = t.user_id  
				  WHERE (t.type_id != '1' and t.type_id != '2') " & HSQL & " 
				  ORDER BY t.log_id DESC ";
				
			queryObj = new Query( datasource=application.dnsSlave );
			
			rs_all = queryObj.execute( sql=sql ).getResult();
			
			/* 生成分页 */
			 pageAdvice.setTotleRow( rs_all.recordCount );
			 pageAdvice.setStartRow( event.getArg("Start", 1) );
			 pageAdvice.setPage( event.getArg("Page", 1) );
			 
			 pageAdvice.setRowPerPage( 20 );
			 
			 pageArray = pageAdvice.getPageList();
			 
			 startRow = pageAdvice.getStartRow();
			 endRow = startRow + pageAdvice.getRowPerPage() - 1;
			 
			
			
	
		}
		
		rs_login = queryNew("");
		/*登录日志*/
		if( currentTab eq "labLogin" ){
			
			typeId = event.getArg("typeId");
			targetId = event.getArg("targetId");
			
			HSQL = "";
			
			if( len(typeId) ){
				HSQL = " AND t.type_id = '" & typeId & "'";	
				
				if( typeId eq '1'){
					tip = "查看教师登录日志";
				}else{
					tip = "查看学生登录日志";
				}
			}
			
			if( len(targetId) ){
				HSQL = " AND t.target_id = '" & targetId & "'";	
				tip = "用户编号" & targetId;
			}
			
			
			sql = "SELECT substr(t.log_id,5,5) log_id, t.type_id, 
						t.user_id, t.log_content, 
						t.log_ip, t.log_time, t.target_id, t.cls_id, 
						b.user_name 
				  FROM T_LOGINFO t 
					  INNER JOIN t_user b ON b.user_id = t.target_id 
				  WHERE (t.type_id = '1' or t.type_id = '2') " & HSQL & "
				  ORDER BY t.log_id DESC ";
				
			queryObj = new Query( datasource=application.dnsSlave, maxRows=60 );
			
			rs_login = queryObj.execute( sql=sql ).getResult();
	
		}
		
		rs_clsAddStudent = queryNew("");
		
		/*教师给班级添加学生日志*/
		if( currentTab eq "labClsAddStudent" ){
			
			tchId = event.getArg("tchId");
			stuId = event.getArg("stuId");
			clsId = event.getArg("clsId");
			
			HSQL = "";
			
			if( len(tchId) ){
				HSQL = " AND t.user_id = '" & tchId & "'";	
				tip = "教师编号" & tchId;
			}
			
			if( len(stuId) ){
				HSQL = " AND t.target_id = '" & stuId & "'";	
				tip = "学生学号" & stuId;
			}
			
			if( len(clsId) ){
				HSQL = " AND t.cls_id = '" & clsId & "'";	
				tip = "班级编号" & clsId;
			}
			
			sql = "SELECT substr(t.log_id,5,5) log_id, t.type_id, 
						t.user_id, t.log_content, 
						t.log_ip, t.log_time, t.target_id, t.cls_id, 
						b.user_name , c.grade 
				  FROM T_LOGINFO t 
					  INNER JOIN t_user b ON b.user_id = t.target_id 
					  INNER JOIN t_class c on c.cls_id = t.cls_id 
				  WHERE t.type_id = '4' " & HSQL & " 
				  ORDER BY t.log_id DESC ";
				
			queryObj = new Query( datasource=application.dnsSlave,maxRows=60 );
			
			rs_clsAddStudent = queryObj.execute( sql=sql ).getResult();
		
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">返回上级</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 report"></i>日志查看
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labOperation">class="active"</cfif> id="labOperation" tabTarget="Operation">日志类别</span>
                              <cfif currentTab eq "labAll"><span class="active" id="labAll" tabTarget="AllLog">所有日志</span></cfif>
						<cfif currentTab eq "labLogin"><span class="active" id="labLogin" tabTarget="Login">登录日志</span></cfif>
                              <cfif currentTab eq "labClsAddStudent"><span class="active" id="labClsAddStudent" tabTarget="ClsAddStudent">班级添加学生日志</span></cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>

				<div id="Operation" class="tabContent">
					
					<div class="noticeBlock">
						<h3>日志汇总</h3>
						<hr/>
					</div>
					
					<div class="clearfix">
						<ul class="UINavBoard">
							<li class="col3 first">
								<div class="board hasPic">
									<cfset structInsert( passArgs, "TabID", "labAll", true ) />
									<a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>">
										<div class="pic">
											<span class="icon48x48 taskTempChange"></span>
										</div>
										<div class="content">
											<h5>日志汇总</h5>
											<p>所有日志汇总</p>
										</div>
									</a>
								</div>
							</li>
							
							
						</ul>
					</div>
				
					
					<div class="noticeBlock">
						<h3>分类日志</h3>
						<hr/>
					</div>
					
					<div class="clearfix">
						<ul class="UINavBoard">
                              
                              	<li class="col3 first">
								<div class="board hasPic">
									<cfset structInsert( passArgs, "TabID", "labLogin", true ) />
									<a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>">
										<div class="pic">
											<span class="icon48x48 sportTask"></span>
										</div>
										<div class="content">
											<h5>登录日志</h5>
											<p>查看学生和老师登录日志</p>
										</div>
									</a>
								</div>
							</li>
                                   
							<li class="col3">
								<div class="board hasPic">
									<cfset structInsert( passArgs, "tabId", "labClsAddStudent", true ) />
									<a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>">
										<div class="pic">
											<span class="icon48x48 teacherChange"></span>
										</div>
										<div class="content">
											<h5>班级添加学生</h5>
											<p>教师给自己班级或者管理员给班级添加学生</p>
										</div>
									</a>
								</div>
							</li>
							
						</ul>
					</div>
                        
				

				</div>
				
                    <div id="AllLog" class="tabContent">
					
					<div class="noticeBlock">
                              <cfif len(tip) >
                              	<cfset structInsert( passArgs, "tabId", "labAll", true ) />
							<h3 style="color:#F0C">以下为日志'&nbsp;<cfoutput>#tip#</cfoutput>&nbsp;'的筛选结果，<a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>">点此查看全部日志</a></h3>
                                	<cfelse>
                                   <h3>所有日志</h3>
                              </cfif>
						<hr/>
					</div>
					
					<cfif rs_All.recordCount>
							<cfset row = 0 />
							<table class="UIEditable">
								<thead>
									<tr>
										<td width="45">编号</td>
                                                  <td width="30">类型</td>
										<td width="50">操作人</td>
										<td >内容</td>
                                                  <td width="100" >对象</td>
										<td>时间</td>
                                                  <td>ip地址</td>
									</tr>
								</thead>
								<tbody>
                                    	<cfloop startrow="#startRow#" endrow="#endRow#" query="rs_All">
								    <cfset structInsert( passArgs, "tabId", "labAll", true ) />
                                            <cfset row++ />
                                            <tr class="editRows">
                                                 <td class="index"><span class="numeric"><cfoutput>#rs_All.log_id#</cfoutput></span></td>
                                                 <cfset structInsert( passArgs, "typeId", rs_All.type_id, true ) />
                                                 <td><span class="numeric"><a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>"><cfoutput>#rs_All.type_id#</cfoutput></a></span></td>
                                                 <cfset structDelete( passArgs, "typeId" ) />
                                                 <cfset structInsert( passArgs, "userId", rs_All.user_id, true ) />
                                                       
                                                 <td> <a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>"><cfoutput>#rs_All.userName#</cfoutput></a></td>
                                                 <td><cfoutput>#rs_All.log_content#</cfoutput></td>
                                                 
                                                  <cfset structDelete( passArgs, "userId" ) />
                                                 <cfset structInsert( passArgs, "targetId", rs_All.target_id, true ) />
                                                 
                                                 <td><a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>"><cfoutput>#rs_All.targetName#</cfoutput></a></td>
                                                 <cfset structDelete( passArgs, "targetId" ) />
                                                 
                                                 <td><span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_All.log_time, 'YYYY-MM-DD HH:MI')#</cfoutput></span></td>
                                                 <td><a href="http://www.baidu.com/s?word=<cfoutput>#rs_All.log_ip#</cfoutput>" target="_blank" title="查看ip归属地"><cfoutput>#rs_All.log_ip#</cfoutput></a></td>
                                                 
                                            </tr>
                                       
                                       </cfloop>
								</tbody>
							</table>
						<cfelse>
							<div class="systemNotice">
								<p>尚无日志记录</p>
							</div>
					</cfif>
                         
                         <div class="pagination">
                         
                              <div class="summary">Page:<cfoutput>#pageAdvice.getPage()#</cfoutput>/<cfoutput>#pageAdvice.getPageCount()#</cfoutput> Totle:<cfoutput>#pageAdvice.getTotleRow()#</cfoutput></div>
                              <div class="lists">
                                   <cfloop from="1" to="#arrayLen(pageArray)#" index="page">
          
                                        <cfset structInsert( pageArgs, "Start", pageArray[page][2], true ) />
                                        <cfset structInsert( pageArgs, "Page", pageArray[page][3], true ) />
                                        <cfset structInsert( pageArgs, "tabId", "labAll", true ) />
                                         <cfset structInsert( pageArgs, "typeId", event.getArg("typeId"), true ) />
                                          <cfset structInsert( pageArgs, "userId", event.getArg("userId"), true ) />
                                           <cfset structInsert( pageArgs, "targetId", event.getArg("targetId"), true ) />
          
                                        <cfswitch expression="#pageArray[page][1]#">
                                             <cfcase value="D">
                                                  <a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>"><cfoutput>#pageArray[page][3]#</cfoutput></a>
                                             </cfcase>
                                             <cfcase value="C">
                                                  <span><cfoutput>#pageArray[page][3]#</cfoutput></span>
                                             </cfcase>
                                             <cfcase value="F">
                                                  <a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">First</a>
                                             </cfcase>
                                             <cfcase value="P">
                                                  <a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Previous</a>
                                             </cfcase>
                                             <cfcase value="N">
                                                  <a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Next</a>
                                             </cfcase>
                                             <cfcase value="L">
                                                  <a href="<cfoutput>#buildURL(event.getName(), pageArgs)#</cfoutput>">Last</a>
                                             </cfcase>
                                        </cfswitch>
                                   </cfloop>
                              </div>
                         </div>
					
				</div>
                    
				<div id="Login" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<!---<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('studentChangeDownloadExcel', passArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载历史记录</span></a>--->
						</div>
                              <cfif len(tip) >
                              	<cfset structInsert( passArgs, "tabId", "labLogin", true ) />
							<h3 style="color:#F0C">以下为日志'&nbsp;<cfoutput>#tip#</cfoutput>&nbsp;'的筛选结果，<a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>">点此查看全部日志</a></h3>
                                	<cfelse>
                                   <h3>用户登录日志</h3>
                              </cfif>
						<hr/>
					</div>
					
					<cfif rs_Login.recordCount>
							<cfset row = 0 />
							<table class="UIEditable">
								<thead>
									<tr>
										<td width="45">编号</td>
										<td width="30">类型</td>
										<td width="60" >姓名</td>
                                                  <td width="100" >号码</td>
										<td >内容</td>
										<td>时间</td>
                                                  <td>ip地址</td>
									</tr>
								</thead>
								<tbody>
                                    <cfloop query="rs_Login" >
										<cfset structInsert( passArgs, "tabId", "labLogin", true ) />
										<cfset row++ />
										<tr class="editRows">
											<td class="index"><span class="numeric"><cfoutput>#rs_Login.log_id#</cfoutput></span></td>
											<td><cfif rs_Login.type_id eq '1'>
                                                       
														<cfset structInsert( passArgs, "typeId", "1", true ) />
                                                                      <a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>">教师</a>
                                                                      
                                                                 <cfelse>
                                                                 
                                                                 	<cfset structInsert( passArgs, "typeId", "2", true ) /> 
                                                                      <a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>">学生</a>
                                                                      
                                                            </cfif>
                                                       </td>
                                                            
                                                       <cfset structDelete( passArgs, "typeId" ) />
                                                       <cfset structInsert( passArgs, "targetId", rs_Login.target_id, true ) />
                                                        
											<td><a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>"><cfoutput>#rs_Login.user_name#</cfoutput></a></td>
                                                       <td><a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>"><cfoutput>#rs_Login.target_id#</cfoutput></a></td>
                                                       <cfset structDelete( passArgs, "targetId" ) />
                                                       
											<td><cfoutput>#rs_Login.log_content#</cfoutput></td>
                                                       <td><span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_Login.log_time, 'YYYY-MM-DD HH:MI')#</cfoutput></span></td>
											<td><a href="http://www.baidu.com/s?word=<cfoutput>#rs_Login.log_ip#</cfoutput>" target="_blank" title="查看ip归属地"><cfoutput>#rs_Login.log_ip#</cfoutput></a></td>
											
										</tr>
									
									</cfloop>
								</tbody>
							</table>
						<cfelse>
							<div class="systemNotice">
								<p>尚无日志记录</p>
							</div>
					</cfif>
					
				</div>
                    
                    <div id="ClsAddStudent" class="tabContent">
					
					<div class="noticeBlock">
                         	<cfif len(tip) >
                              	<cfset structInsert( passArgs, "tabId", "labClsAddStudent", true ) />
							<h3 style="color:#F0C">以下为日志'&nbsp;<cfoutput>#tip#</cfoutput>&nbsp;'的筛选结果，<a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>">点此查看全部日志</a></h3>
                                	<cfelse>
                                   <h3>教师给班级添加学生日志</h3>
                              </cfif>
						<hr/>
					</div>
					
					<cfif rs_clsAddStudent.recordCount>
							<cfset row = 0 />
							<table class="UIEditable">
								<thead>
									<tr>
										<td width="45">编号</td>
                                                  <td >内容</td>
										<td >教师编号</td>
										<td >学生学号</td>
                                                  <td >班级编号</td>
                                                  <td >年级</td>
										<td>时间</td>
                                                  <td>ip地址</td>
									</tr>
								</thead>
								<tbody>
                                         <cfloop query="rs_clsAddStudent" >
									    <cfset structInsert( passArgs, "tabId", "labClsAddStudent", true ) />
                                                 
                                                 <cfset row++ />
                                                 <tr class="editRows">
                                                      <td class="index"><span class="numeric"><cfoutput>#rs_clsAddStudent.log_id#</cfoutput></span></td>
                                                      <td><cfoutput>#rs_clsAddStudent.log_content#</cfoutput></td>
                                                      
                                                      <cfset structInsert( passArgs, "tchId", rs_clsAddStudent.user_id, true ) />
                                                      
                                                      <td><a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>"><cfoutput>#rs_clsAddStudent.user_id#</cfoutput></a></td>
                                                      <cfset structDelete( passArgs, "tchId" ) />
                                                      <cfset structInsert( passArgs, "stuId", rs_clsAddStudent.target_id, true ) />
                                                      
                                                      <td><a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>"><cfoutput>#rs_clsAddStudent.target_id#</cfoutput></a></td>
                                                      
                                                      <cfset structDelete( passArgs, "stuId" ) />
                                                      <cfset structInsert( passArgs, "clsId", rs_clsAddStudent.cls_id, true ) />
                                                      
                                                      <td><a href="<cfoutput>#buildURL('logView', passArgs)#</cfoutput>"><cfoutput>#rs_clsAddStudent.cls_id#</cfoutput></a></td>
                                                       <cfset structDelete( passArgs, "clsId" ) />
                                                       
                                                      <td><cfoutput>#rs_clsAddStudent.grade#</cfoutput></td>
                                                      <td><span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_clsAddStudent.log_time, 'YYYY-MM-DD HH:MI')#</cfoutput></span></td>
                                                      <td><a href="http://www.baidu.com/s?word=<cfoutput>#rs_clsAddStudent.log_ip#</cfoutput>" target="_blank" title="查看ip归属地"><cfoutput>#rs_clsAddStudent.log_ip#</cfoutput></a></td>
                                                      
                                                 </tr>
                                                  
									</cfloop>
								</tbody>
							</table>
						<cfelse>
							<div class="systemNotice">
								<p>尚无日志记录</p>
							</div>
					</cfif>
					
				</div>

				
			</div>
		</li>
	</ul>
</div>